package com.hyh.util;

import android.app.ActivityManager;
import android.app.ApplicationErrorReport;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import java.util.List;

/**
 * Created by Administrator on 2019/1/28.
 */

public class ServiceUtil {

    public static boolean isServiceRunning(Context context,String serviceName){
        if(TextUtils.isEmpty(serviceName)){
            return false;
        }
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> runningServiceInfoList = activityManager.getRunningServices(30);
        for (ActivityManager.RunningServiceInfo runningServiceInfo:runningServiceInfoList){
            String name = runningServiceInfo.service.getClassName().toString();
            if(name.equals(serviceName)){
                return true;
            }
        }
        return false;
    }
}
